package org.ljy.lotterysystem.dao.mapper;

import org.apache.ibatis.annotations.*;
import org.ljy.lotterysystem.dao.dataobject.ActivityDO;

import java.util.List;

/**
 * 活动关联表
 */

@Mapper
public interface ActivityMapper {


    /**
     * 新增活动
     * @param activityDO
     */
    @Insert("insert into activity (activity_name, description, status)" +
            " values (#{activityName},#{description},#{status})")
    @Options(useGeneratedKeys = true,keyProperty = "id",keyColumn = "id")
    void insert(ActivityDO activityDO);



    /**
     * 查询活动总数
     * @return
     */
    @Select("select count(1) from activity")
    int count();

    /**
     *  获取活动列表
     * @param offset 偏移量
     * @param pageSize 查询的个数
     * @return 活动列表
     */
    @Select("select * from activity order by id desc limit #{offset},#{pageSize}")
    List<ActivityDO> findActivityList(@Param("offset") Integer offset, @Param("pageSize")Integer pageSize);

    @Select("select * from activity where id=#{id}")
    ActivityDO selectByActivityId(@Param("id") Long id);

    /**
     * 修改活动状态
     * @param activityId
     * @param status
     */
    @Update("update activity set status = #{status} where id = #{activityId}")
    void updateStatus(@Param("activityId")Long activityId,@Param("status")String status);
}
